//Copyright (c) 2012 The cwkshell Authors. All rights reserved. 
// Use of this source code is governed by a BSD-style license that can be 
// found in the LICENSE file. 
#include "cuc/src/cwkshell/browser/jsextension/cuc_object.h" 

#include <string>

#include "grit/cwkshell_files_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "cuc/src/cwkshell/browser/shell_browser.h" 
#include "cuc/src/cwkshell/view/shell_browser_container.h"
#include "cuc/src/cwkshell/browser/shell_messages.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/browser_thread.h"
namespace cuc{ 
	namespace shell{ 

		namespace{

			const char* ToCString(const v8::String::Utf8Value& value) {
				return *value ? *value : "<string conversion failed>";
			}
			base::StringPiece GetStringResource(int resource_id) {
				return ResourceBundle::GetSharedInstance().GetRawDataResource(
					resource_id);
			}
			v8::Handle<v8::Value> Version(const v8::Arguments& args){		
				return v8::String::New("0.1.87");
			}
			v8::Handle<v8::Value> Quit(const v8::Arguments& args){		

				return v8::Undefined();
			}
			/*
			v8::Handle<v8::Value> ExcuteBrowserContainerFunctions(const v8::Arguments& args){		
		
				if(args[0]->IsString()){
			
					v8::String::Utf8Value str(args[0]);
					std::string func(*str);
					ShellBrowser::instance()->GetShellBrowserContainer()->web_contents()->GetRenderViewHost()->ExecuteJavascriptAndGetValue('',func+';');
				}
				//ShellBrowser::instance()->GetShellBrowserContainer()->web_contents()->
				return v8::Undefined();
			}
			*/
		}
		CUCObject::CUCObject():
		v8::Extension("cuc/CUCObject",
			GetStringResource(
			IDR_FILES_JSEXTENSION_CUCOBJECT_CUCOBJECT_JS).data(),
			0,     // num dependencies.
			NULL,  // dependencies array.
			GetStringResource(
			IDR_FILES_JSEXTENSION_CUCOBJECT_CUCOBJECT_JS).size())
		{
		}
		CUCObject::~CUCObject(){

		}
		v8::Handle<v8::FunctionTemplate>
			CUCObject::GetNativeFunction(v8::Handle<v8::String> name){
				if (name->Equals(v8::String::New("Version")))
					return v8::FunctionTemplate::New(Version);
				if (name->Equals(v8::String::New("Quit")))
					return v8::FunctionTemplate::New(Quit);
				  return v8::FunctionTemplate::New();
		}
	} //namespace shell 
} //namespace cuc 
